<template>
  <div class="bazijp-pay">
    <div class="bazijp-pay">
      <div class="bazijp-pay__basic-info">
        <div class="three-part">
          <div style="padding-top: 30px; color: #ffebac">
            资深易学研究者
            <span style="color: #c95907">玄青老师</span>
            根据你的生日量身定制的分析报告，内容涵盖姻缘、运势方方面面，已有
            <span style="color: #c95907"> 247353</span>
            人购买，好评率高达
            <span style="color: #c95907"> 95.43%</span>
            !
          </div>
          <div style="text-align: center; padding: 20px 0; color: #ffebac">
            <h2>输入手机号永久保存结果</h2>
          </div>
        </div>

        <form
          class="bazijp__form"
          @submit.prevent="onSubmit()"
          ref="ruleFrom"
          :model="form"
          :rules="rules"
        >
          <div>
            <div style="padding: 20px 0 20px 12px; color: #c95907">
              <el-icon style="color: red; margin-top;: 4px "
                ><Select
              /></el-icon>
              保存测算结果
            </div>
            <div>
              <!-- <label style="width: 100px !important">您的手机号：</label> -->
              <input
                type="text"
                placeholder="请输入手机号保存"
                v-model="form.phoneNumber"
                @focus="handleInputFocus"
                @blur="handleInputBlur"
                style="
                  width: 100%;
                  border-radius: 18px;
                  height: 36px;
                  line-height: 36px;
                  border-color: #1677ff;
                "
              />
            </div>
          </div>

          <div class="pay-channels" @click="onSubmit()" style="margin: 20px 0">
            <a class="alipay"> 领取测算并查看结果 </a>
          </div>
          <div class="pay-channels" @click="onSubmitAdd()">
            <a class="alipay"> 点击添加客服 </a>
          </div>
        </form>
        <div
          style="
            margin-top: 40px;
            display: flex;
            justify-content: space-between;
          "
        >
          <div class="picBox">
            <img src="../../assets/index_static/780.png" alt="" width="40" />
            <div style="padding-top: 10px">付款成功</div>
          </div>
          <div style="color: #1677ff; padding-top: 30px">
            <el-icon><DArrowRight /></el-icon>
          </div>
          <div class="picBox">
            <img src="../../assets/index_static/781.jpg" alt="" width="40" />
            <div style="padding-top: 10px">添加老师</div>
          </div>
          <div style="color: #1677ff; padding-top: 30px">
            <el-icon><DArrowRight /></el-icon>
          </div>
          <div class="picBox">
            <img src="../../assets/index_static/order.png" alt="" width="40" />
            <div style="padding-top: 10px">查询订单</div>
          </div>
          <div style="color: #1677ff; padding-top: 30px">
            <el-icon><DArrowRight /></el-icon>
          </div>
          <div class="picBox">
            <img src="../../assets/index_static/finish.png" alt="" width="40" />
            <div style="padding-top: 10px">获取结果</div>
          </div>
        </div>
      </div>

      <!-- <img src="../../assets/pic//basic_bottom.png" width="100%" /> -->
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from "vue";
import axios from "axios";

const ruleForm = ref(null);
const afterSubmit = ref(true);
const form = ref({
  phoneNumber: "",
});
const rules = {
  phoneNumber: [
    { required: true, message: "请输入手机号", trigger: "blur" },
    {
      validator: (rule, value, callback) => {
        const phoneRegex = /^1[3-9]\d{9}$/;
        if (!value) {
          callback(new Error("请输入手机号"));
        } else if (!phoneRegex.test(value)) {
          callback(new Error("请输入有效的手机号"));
        } else {
          callback(); // 校验通过
        }
      },
      trigger: "blur",
    },
  ],
};
const validateName = (number) => {
  const phoneRegex = /^1[3-9]\d{9}$/;
  if (!number) {
    alert("请输入手机号");
    return false;
  }
  // 验证姓名格式
  if (!phoneRegex.test(number)) {
    alert("请输入有效的手机号");
    return false;
  }
  return true;
};
const onSubmit = () => {
  if (form.value.phoneNumber) {
    if (!validateName(form.value.phoneNumber)) {
      return;
    }
    const wechatOrderNum = localStorage.getItem("orderId");
    const data = {
      id: wechatOrderNum,
      phoneNumber: form.value.phoneNumber,
      bdVid: localStorage.getItem("bdVid") ? localStorage.getItem("bdVid") : "",
    };
    axios
      .post("/api/order/update", data)
      .then((res) => {
        window.location.href = "https://tz.dakw.xyz/ss/11.html?tkey=3f0e6fae34";
      })
      .catch((error) => {
        console.error("获取 IP 地址失败：", error);
      });
  } else {
    alert("请输入手机号");
  }

  // http://121.89.85.110:6000/api/order/update
  // afterSubmit.value = false;
  // router.push("/dashboard");
};
// 防止 iOS 输入框缩放的方法
const handleInputFocus = () => {
  // 禁用缩放
  document.body.style.zoom = "1";
  document.body.style.transform = "scale(1)";
  document.body.style.transformOrigin = "0 0";
};

const handleInputBlur = () => {
  // 恢复缩放
  document.body.style.zoom = "";
  document.body.style.transform = "";
  document.body.style.transformOrigin = "";
};
const onSubmitAdd = () => {
  window.location.href = "https://tz.dakw.xyz/ss/11.html?tkey=3f0e6fae34";
};
const addKefu = () => {
  // router.push("/addKefu");
};
</script>

<style scoped>
@import url("../../assets/index_static/app.css");

.picBox {
  width: 60px;
  height: 60px;
  color: #c95907;
  border: 1px solid #c95907;
  border-radius: 4px;
  text-align: center;
  padding: 14px 10px;
  font-size: 14px;
}
</style>
